package java2020spring;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;
import javax.swing.undo.UndoManager;
public class EditListener implements ActionListener{
	JTextArea txt;
	UndoManager manager;
	JMenuItem about;
	public void setAoubt(JMenuItem about) {
		this.about=about;
	}
	public void setTxt(JTextArea area) {
		txt=area;
	}
	public void setUndoManager(UndoManager undoManager) {
		manager=undoManager;
	}
	public void actionPerformed(ActionEvent e) {
		txt.getDocument().addUndoableEditListener(manager);
		String s=e.getActionCommand().toString();
		if(s.equals("copy")) {
			txt.copy();
		}
		else if(s.equals("zhantie")) {
			txt.paste();
		}
		else if(s.equals("cut")) {
			txt.cut();
		}
		else if(s.equals("chexiao")||manager.canUndo()) {
			manager.undo();
		}
		
	}
}
